﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using MoqContrib.AutoMock.CommonServiceLocator;

namespace MoqContrib.AutoMock.CommonService.Tests.ClassAnalyzerTests
{
	[TestFixture]
	public class WhenClassHasMultipleConstructors
	{
		#region Types used for testing
		public interface IService{}
		public class WithAnObviousChoice
		{
			public WithAnObviousChoice()
			{
				Code = 1;
			}
			public WithAnObviousChoice(IService service)
			{
				Service = service;
				Code = 2;
			}
			public int Code { get; set; }
			public IService Service { get; set; }
		}
		public class WithOneUnresolvableAndAnotherResolvable
		{
			public WithOneUnresolvableAndAnotherResolvable(string s)
			{
				Code = 1;
			}
			public WithOneUnresolvableAndAnotherResolvable(IService s)
			{
				Code = 2;
				Service = s;
			}
			public int Code { get; set; }
			public IService Service { get; set; }
		}
		#endregion

		private ClassAnalyzer sut;

		[SetUp]
		public void Given()
		{
			sut = new ClassAnalyzer();
			sut.Helper = new CommonServiceLocator.AutoMockHelper();
		}

		[Test]
		public void I_use_the_ctor_with_the_most_args()
		{
			var result = sut.Construct<WithAnObviousChoice>();
			Assert.That(result.Code, Is.EqualTo(2));
			Assert.That(MockingUtilities.GetMockFor(result.Service), Is.Not.Null);
		}

		[Test]
		public void I_use_the_best_ctor_that_I_can_construct()
		{
			var result = sut.Construct<WithOneUnresolvableAndAnotherResolvable>();
			Assert.That(result.Code, Is.EqualTo(2));
			Assert.That(MockingUtilities.GetMockFor(result.Service), Is.Not.Null);
		}
	}
}
